package algorithmTopics.link;

/**
 * “列表” 节点
 *
 * @author 86155
 * @date 2025/05/11
 */
public class ListNode {
    int val;
    ListNode next;
    ListNode() {}
    ListNode(int val) { this.val = val; }
    ListNode(int val, ListNode next) { this.val = val; this.next = next; }


    // 尾插法
    public void add(int data) {
        ListNode now = this;
        while (now.next != null) {
            now = now.next;
        }
        ListNode listNode = new ListNode(data);
        now.next = listNode;
    }

    public void output() {
        ListNode now = this;
        while (now != null) {
            System.out.print(now.val + ",");
            now = now.next;
        }
    }


}
